<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="__PUBLIC__/easyui/jquery.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/easyui/locale/easyui-lang-zh_CN.js"></script>
<link rel="stylesheet" type="text/css" href="__PUBLIC__/easyui/themes/gray/easyui.css">
<link rel="stylesheet" type="text/css" href="__PUBLIC__/easyui/themes/icon.css">
<script type="text/javascript">
$(function(){
	/*已提交流程*/
	$("#t1").datagrid({
		url:'__APP__/Process/getPersonalProcess',
		fit:true,
		pagination:true,
		pageSize:15,
		pageList:[15,20,25,30],
	 	fitColumns:true,
        iconCls:'icon-edit',
        singleSelect:true,
        rownumbers:true,
        idField:'process_id',
        columns:[[
        	{field:'process_num',title:'流程号',width:100},
        	{field:'process_title',title:'流程名',width:300},
        	{field:'process_type',title:'流程类型',width:100}
         ]],
         toolbar:[{  
             text:'查看详情',  
             iconCls:'icon-tip',  
             handler:function(){processContent(1)}
        },'-',{  
             text:'流程状态',  
             iconCls:'icon-tip',  
             handler:processState
        }]
	});
	/*未提交流程*/
	$("#t2").datagrid({
		url:'__APP__/Process/getPersonalProcess1',
		fit:true,
		pagination:true,
		pageSize:15,
		pageList:[15,20,25,30],
	 	fitColumns:true,
        iconCls:'icon-edit',
        singleSelect:true,
        rownumbers:true,
        idField:'process_id',
        columns:[[
			{field:'process_num',title:'流程号',width:100},
        	{field:'process_title',title:'流程名',width:300},
        	{field:'process_type',title:'流程类型',width:100}
         ]],
         toolbar:[{  
             text:'查看详情',  
             iconCls:'icon-tip',  
             handler:function(){processContent(2)}
         },'-',{  
             text:'提交流程',  
             iconCls:'icon-save', 
             handler:submitProcess
         }  
         ]
	});
});

/*查看流程详情函数*/
function processContent(tag){
   //根据tag判断是已提交流程还是保存流程
   if(1==tag){
        var process=$("#t1").datagrid("getSelected");
   }else if(2==tag){
        var process=$("#t2").datagrid("getSelected");
   }

   var processType=process.process_type.toLowerCase();;//流程类型
   $('#dlg').dialog(
        {
            closed:false,
            href:'__URL__/getProcessContent/processType/'+processType+'/processId/'+process.process_id
        }
    );
}

/*查看流程状态函数*/
function processState(){
     var data=$("#t1").datagrid("getSelected");
    if(null==data){
        $.messager.alert('提示','请选择一条流程记录','warning');
        return false;
    }else{
        $.post('__APP__/Process/processState',{processID:data.process_id},function(r){
           alert(r);
        });
    }
}

/*提交流程函数*/
function submitProcess(){
    var data=$("#t2").datagrid("getSelected");
    if(null==data){
        $.messager.alert('提示','请选择一条流程记录','warning');
        return false;
    }else{
        $.messager.confirm('提示', '确认提交流程', function(r){
            if (r){
                $.messager.progress({text:'正在提交，请稍等...'}); 
                 var processType=data.process_type.toLowerCase();;//流程类型
                $.post("__APP__/Process/submitProcess",{processID:data.process_id,processType:processType},function(r){
                    if(0==r){
                        $.messager.progress('close'); 
                        $.messager.alert('提示','提交失败','warning');
                    }else{
                        $.messager.progress('close'); 
                        $.messager.alert('提示','提交成功');
                        window.location="__APP__/Process/personalProcess";      
                    }
                });
            }
        });             
    }
}
</script>
</head>
<body>
	<div class="easyui-tabs" data-options="fit:true">    
		<div title="已提交流程">
			<table id="t1"></table>
		</div>    
		<div title="未提交流程">
			<table id="t2"></table>
		</div>
	</div>
    <div id="dlg" class="easyui-dialog"  style="width:600px;height:400px;"  buttons="#dlg-buttons" closed='true' 
    title="物品领用详细列表">
    </div>
</body>
</html>